package com.itheima.goods.controller;

import com.itheima.goods.pojo.Spec;
import com.itheima.goods.service.SpecService;
import entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/spec")
@CrossOrigin
public class SpecController {

    @Autowired
    private SpecService specService;

    @GetMapping
    public Result findAll(){
        return specService.findAll();
    }

    @PostMapping
    public Result add(Spec spec){
        return specService.add(spec);
    }

    @GetMapping("/search/{page}/{size}")
    public Result findPage(@PathVariable("size") Integer size,@PathVariable("page") Integer page){
        return specService.findPage(size,page);
    }

    @GetMapping("/{id}")
    public Result findById(Integer id){
        return specService.findById(id);
    }

    @PutMapping("/{id}")
    public Result update(Spec spec,Integer id){
        return specService.update(id,spec);
    }

    @DeleteMapping("/{id}")
    public Result delete(Integer id){
        return specService.delete(id);
    }
}
